package com.gzhryc.test.kafka;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import com.gzhryc.common.json.JsonTools;

import com.gzhryc.common.kafka.KafkaProducerFactory;
import com.gzhryc.common.kafka.models.KafkaMessage;
import com.gzhryc.test.kafka.entity.CdbData;

public class KafkaProducerMain {

    public static void main(String[] args) throws IOException {
        //  配置信息
        Properties properties = new Properties() ;
        properties.load(KafkaProducerMain.class.getClassLoader().getResourceAsStream( "procuder.properties"));

        System.out.println(properties.get("bootstrap.servers"));
        
        KafkaProducerFactory.self().initial(properties) ;

		List<KafkaMessage> orderMessageList = new ArrayList<>() ;

		CdbData cdbData = new CdbData() ;
		cdbData.setIncidentTime( new Date() ) ;
		cdbData.setPortableBatterySn( "DZL1911112591" ) ;
		cdbData.setRevertChargingCabinetSn( "DZLB200083" ) ;
		cdbData.setProjectId( "10019" ) ;
		String jsonList = JsonTools.toJson(cdbData) ;
		KafkaMessage orderException = new KafkaMessage("orderException" ,"orderException", jsonList ) ;
		orderMessageList.add( orderException ) ;

		cdbData.setIncidentTime( new Date() ) ;
		cdbData.setPortableBatterySn( "DZL1911110292" ) ;
		cdbData.setRevertChargingCabinetSn( "DZLB100216" ) ;
		cdbData.setProjectId( "10019" ) ;
		jsonList = JsonTools.toJson(cdbData) ;
		orderException = new KafkaMessage("orderException" ,"orderException", jsonList ) ;
		orderMessageList.add( orderException ) ;

		cdbData.setIncidentTime( new Date() ) ;
		cdbData.setPortableBatterySn( "DZL1911110650" ) ;
		cdbData.setRevertChargingCabinetSn( "DZLB200074" ) ;
		cdbData.setProjectId( "10019" ) ;
		jsonList = JsonTools.toJson(cdbData) ;
		orderException = new KafkaMessage("orderException" , "orderException",jsonList ) ;
		orderMessageList.add( orderException ) ;

		cdbData.setIncidentTime( new Date() ) ;
		cdbData.setPortableBatterySn( "DZL1911111104" ) ;
		cdbData.setRevertChargingCabinetSn( "DZLB200095" ) ;
		cdbData.setProjectId( "10019" ) ;
		jsonList = JsonTools.toJson(cdbData) ;
		orderException = new KafkaMessage("orderException" , "orderException" ,jsonList ) ;
		orderMessageList.add( orderException ) ;

		cdbData.setIncidentTime( new Date() ) ;
		cdbData.setPortableBatterySn( "DZL1911110651" ) ;
		cdbData.setRevertChargingCabinetSn( "DZLB200074" ) ;
		cdbData.setProjectId( "10019" ) ;
		jsonList = JsonTools.toJson(cdbData) ;
		orderException = new KafkaMessage("orderException" ,"orderException" , jsonList ) ;
		orderMessageList.add( orderException ) ;

		cdbData.setIncidentTime( new Date() ) ;
		cdbData.setPortableBatterySn( "DZL1911111056" ) ;
		cdbData.setRevertChargingCabinetSn( "DZLB200074" ) ;
		cdbData.setProjectId( "10019" ) ;
		jsonList = JsonTools.toJson(cdbData) ;
		orderException = new KafkaMessage("orderException" ,"orderException" , jsonList ) ;
		orderMessageList.add( orderException ) ;

		cdbData.setIncidentTime( new Date() ) ;
		cdbData.setPortableBatterySn( "DZL1911110042" ) ;
		cdbData.setRevertChargingCabinetSn( "DZLB100194" ) ;
		cdbData.setProjectId( "10019" ) ;
		jsonList = JsonTools.toJson(cdbData) ;
		orderException = new KafkaMessage("orderException" , "orderException" ,jsonList ) ;
		orderMessageList.add( orderException ) ;

		cdbData.setIncidentTime( new Date( new Date().getTime() - 69 * 60 * 1000 ) ) ;
		cdbData.setPortableBatterySn( "DZL1911113575" ) ;
		cdbData.setRevertChargingCabinetSn( "DZLB100071" ) ;
		cdbData.setProjectId( "10019" ) ;
		jsonList = JsonTools.toJson( cdbData ) ;
		orderException = new KafkaMessage("orderException" , "orderException" ,jsonList ) ;
		orderMessageList.add( orderException ) ;

		for ( int i = 0 ; i < orderMessageList.size() ; i++){
			KafkaProducerFactory.self().getProducer().send( orderMessageList.get(i) ) ;
		}

	}
}
